package edu.hawaii.its381b.client;

import com.google.gwt.core.client.GWT;


//This is mostly a function. It takes the cpab's X,Y location on the map,
// and returns what speed the crab would go. 
public class SpeedArray {

// Set speed over each terrain type. Higher = faster
	private int sand = 5, reef = 2, coral = 1;
	
//this short hand version is to make the array map readable.
//select "rf" in the while in the editor and the reef walls are high-lighted.
	private int sd = sand, rf = reef, cl = coral;

	private int ArrayX,ArrayY;	
	
	//This is the speed to return when checking what the crab is on
	int currentSpeed = sand;

	//Crab size in pixel height and width, and distance in pixels to the center
	int crabSize = 50;
	int crabCenter = crabSize/2;
	
	private int rowsAcross = 30;
	private int columnsAcross = 30;
	
	//The crab "travels" over the array below.
	//The higher the ground type's value, the faster the crab moves in that grid. 
	//The value of the type is how many pixels it moves in one step while in that grid.
	private int mapSpeed[][] = {
    {rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf},
    {rf,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,rf,sd,sd,sd,sd,sd,sd,cl,sd,sd,sd,sd,rf,rf,rf,rf,sd,rf},
    {rf,sd,sd,sd,sd,sd,sd,sd,sd,rf,sd,sd,rf,sd,sd,cl,rf,sd,sd,sd,sd,sd,sd,sd,sd,rf,sd,sd,sd,rf},
    {rf,sd,sd,sd,sd,rf,sd,sd,sd,cl,sd,sd,sd,sd,sd,rf,rf,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,rf},
    {rf,sd,sd,sd,sd,rf,sd,sd,sd,rf,sd,sd,sd,sd,sd,sd,sd,sd,sd,cl,rf,sd,sd,rf,rf,rf,sd,sd,sd,rf},
    {rf,sd,sd,rf,rf,rf,rf,rf,sd,rf,rf,rf,rf,cl,sd,sd,sd,sd,sd,rf,rf,sd,sd,rf,cl,rf,sd,sd,sd,rf},
    {rf,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,sd,s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sd,sd,sd,sd,sd,sd,rf,sd,sd,sd,sd,rf},
    {rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf,rf}
    };

	public int getRows(){
		return rowsAcross;
	}
	
	public int getColumns(){
		return columnsAcross;
	}
	
	public SpeedArray(int speedModifier) {
	// After the speed map is created, this section is used to +-modify the speeds of the entire map 
        for(int row=0; row < rowsAcross ; row++){
            for (int column=0; column < columnsAcross; column++){
            	//Never go below 1
            	if (this.mapSpeed[row][column] + speedModifier < 1){
            		this.mapSpeed[row][column] = 1;            		
            	}else{
            	this.mapSpeed[row][column] = this.mapSpeed[row][column] + speedModifier;
            	}
            }
        }
	}

//	Get the crab map location, return the speed on that terrain 
	public int getMapSpeed(int crabLocationX, int crabLocationY){
		this.ArrayX = (crabLocationX + crabCenter)/50;
		this.ArrayY = (crabLocationY + crabCenter)/50;
		this.currentSpeed = this.mapSpeed[this.ArrayY][this.ArrayX];
		
		//Never return 0. The crab could stick in place.
		if ( this.currentSpeed < 1){
			this.currentSpeed = 1;
		}
		return this.currentSpeed; 
	}
	
}
